package com.applancer.provider;

import java.util.regex.Pattern;

import android.app.Activity;
import android.content.res.Resources;
import android.util.TypedValue;

public class StringUtils {

	public static boolean invalidString(String s) {
		return !validString(s);
	}

	public static boolean validString(String s) {
		if (s == null) {
			return false;
		}
		if (s.trim().equalsIgnoreCase("")) {
			return false;
		}
		return true;
	}

	public static boolean acceptString(String s) {

		Pattern p = Pattern.compile("[^A-Za-z0-9]");
		if (p.matcher(s).find()) {
			return false;
		}

		return true;
	}

	public static String degToCompass(int num) {
		double val = Math.floor((num / 22.5) + 0.5);
		String arr[] = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",
				"SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
		// String arr[] = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
		// "S",
		// "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
		return arr[(int) (val % 16)];
	}

	public static String urlIconWeather(String code) {
		return "http://l.yimg.com/a/i/us/we/52/" + code + ".gif";
	}

	public static int getNavigationBarHeigh(Activity activity){
		Resources resources = activity.getResources();
		int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
		if (resourceId > 0) {
		    return resources.getDimensionPixelSize(resourceId);
		}
		return 0;
	}
	
	public static int getStatusBarHeight(Activity activity) {
		int statusBarHeight = 0;

		int resourceId = activity.getResources().getIdentifier(
				"status_bar_height", "dimen", "android");
		if (resourceId > 0) {
			statusBarHeight = activity.getResources().getDimensionPixelSize(
					resourceId);
		}

		return statusBarHeight;
	}

	public static int getActionbarHeight(Activity activity) {
		TypedValue tv = new TypedValue();
		int actionBarHeight = 0;
		if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize,
				tv, true)) {
			actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
					activity.getResources().getDisplayMetrics());
		}

		return actionBarHeight;
	}

}
